// JavaScript Document
function tab(id,title,cont) {//选项卡ID， title的classname， 下方详情的classname
    var tools=hxsd_tools();
    var oBox=document.getElementById(id);
    var oUl=tools.getClassName(oBox,title);
    var aLi=oUl[0].getElementsByTagName('li');
    var aCont=tools.getClassName(oBox,cont);
    for(var i=0; i<aLi.length; i++){
        aLi[i].index=i;
        aLi[i].onclick=function(){
            for(var j=0; j<aLi.length; j++){
                aLi[j].className='';
                aCont[j].className='cont';
            }
            this.className='active';
            aCont[this.index].className='cont active';
        }
    }
}

function pictab() {
    var tools=hxsd_tools();
    var oLpic=document.getElementById('l_pic');
    var oZpic=document.getElementById('z_pic');
    var oBox=document.getElementById('s_pics');
    var oPrev=tools.getClassName(oBox,'prev')[0];
    var oNext=tools.getClassName(oBox,'next')[0];
    var oSpics=tools.getClassName(oBox,'piclist')[0];
    var oUl=oSpics.getElementsByTagName('ul')[0];
    var aLi=oUl.getElementsByTagName('li');
    oUl.style.width=(aLi[0].offsetWidth+8)*aLi.length+'px';
    var n=0;
    oNext.onclick=function () {
        n++;
        if(n>aLi.length-5){n=aLi.length-5;this.style.backgroundPosition='-70px -346px';}
        if(n!=0){oPrev.style.backgroundPosition='0px -346px';}
        var l=n*(aLi[0].offsetWidth+8);
        oUl.style.left=-l+'px';
    }
    oPrev.onclick=function () {
        n--;
        if(n<0){n=0;this.style.backgroundPosition='-56px -346px';};
        if(n<aLi.length-5){oNext.style.backgroundPosition='-14px -346px';}
        var l=n*(aLi[0].offsetWidth+8);
        oUl.style.left=-l+'px';
    }
    oNext.onmouseover=function(){
        this.style.backgroundPosition='-43px -346px';
        if(n==aLi.length-5){this.style.backgroundPosition='-70px -346px'}
    }
    oNext.onmouseout=function(){
        this.style.backgroundPosition='-14px -346px';
        if(n==aLi.length-5){this.style.backgroundPosition='-70px -346px'}
    }
    oPrev.onmouseover=function(){
        this.style.backgroundPosition='-28px -346px';
        if(n==0){this.style.backgroundPosition='-56px -346px'}
    }
    oPrev.onmouseout=function(){
        this.style.backgroundPosition='0px -346px';
        if(n==0){this.style.backgroundPosition='-56px -346px'}
    }
    for(var i=0; i<aLi.length; i++){
        aLi[i].index=i;
        aLi[i].onmouseover=function () {
            for(var j=0; j<aLi.length; j++){
                aLi[j].className='';
            }
            this.className='active';
            oLpic.innerHTML=this.innerHTML;
            oZpic.innerHTML=oLpic.innerHTML;
        }
    }
    return false;
}

//放大镜
function zoompic(id1,id2,id3,id4){//主体ID ， 放大后图片ID ， 放大后图片外盒子ID ， 放大镜ID 。
    var oDiv1=document.getElementById(id1);
    var oDiv2=document.getElementById(id2);
    var oSpan=document.getElementById(id3);

    oDiv1.onmousemove=function(ev){
        oEv=ev||window.event;
        var oImg=oDiv2.children[0];
        oSpan.style.display='block';
        oDiv2.style.display='block';
        var scroll_top;
        if (document.documentElement && document.documentElement.scrollTop){
            scroll_top = document.documentElement.scrollTop;
        }
        else if (document.body){
            scroll_top = document.body.scrollTop;
        };
        var scroll_left;
        if (document.documentElement && document.documentElement.scrollLeft){
            scroll_left = document.documentElement.scrollLeft;
        }
        else if (document.body){
            scroll_left = document.body.scrollLeft;
        };
        var l = oEv.clientX+scroll_left-oDiv1.offsetLeft-oSpan.offsetWidth/2;
        var t = oEv.clientY+scroll_top-oDiv1.offsetTop-oSpan.offsetHeight/2;

        if(l<=0){
            l=0;
        }
        if(l>=oDiv1.offsetWidth-oSpan.offsetWidth){
            l=oDiv1.offsetWidth-oSpan.offsetWidth;
        }
        if(t<=0){
            t=0;
        }
        if(t>=oDiv1.offsetHeight-oSpan.offsetHeight){
            t=oDiv1.offsetHeight-oSpan.offsetHeight;
        }
        oSpan.style.left=l+'px';
        oSpan.style.top=t+'px';

        var sizeX = l/(oDiv1.offsetWidth-oSpan.offsetWidth);
        var sizeY = t/(oDiv1.offsetHeight-oSpan.offsetHeight);
        oImg.style.left=-(oImg.offsetWidth-oDiv2.offsetWidth)*sizeX+'px';
        oImg.style.top=-(oImg.offsetHeight-oDiv2.offsetHeight)*sizeY+'px';
        return false;
    }
    oDiv1.onmouseout=function(){
        oSpan.style.display='none';
        oDiv2.style.display='none';
    }
}

//点击切换样式
function choose(cls,toggle) {
    var tools=hxsd_tools();
    var oBox=document.getElementById('choosebox');
    var oElm=tools.getClassName(oBox,cls);
    var oDiv=tools.getClassName(oElm[0],'dd');
    var aLi=oDiv[0].getElementsByTagName('li');
    for(var i=0; i<aLi.length; i++){
        aLi[i].index=i;
        aLi[i].open=true;
        aLi[i].onclick=function () {
            for(var j=0; j<aLi.length; j++){
                aLi[j].className=''
            }
            if(toggle){
                if(this.open){
                    for(var k=0; k<aLi.length; k++){
                        aLi[k].open=true;
                    }
                    this.className='active';
                    this.open=false;
                }else{
                    this.open=true;
                    this.className='';
                }
            }else{
                this.className='active';
            }
            console.log(open);
        }
    }
}


//数量加减
function numbox(id){
    var tools=hxsd_tools();
    var oBox=document.getElementById(id);
    var oNum=tools.getClassName(oBox,'change');
    var oPlus=tools.getClassName(oBox,'plus');
    var oMinus=tools.getClassName(oBox,'minus');
    var n=1;
    n = parseInt(oNum[0].value);
    month();
    oNum[0].onkeyup=function(){
        n = parseInt(oNum[0].value);
        if(n<1||isNaN(n)){n=1;this.value=1;}
        month();
    }
    oPlus[0].onclick=function() {
        // n = parseInt(oNum[0].value);
        n++;
        oNum[0].value = n;
        month()
    }
    oMinus[0].onclick=function() {
        // n = parseInt(oNum[0].value);
        n--;
        if (n < 1)n = 1;
        oNum[0].value = n;
        month()
    }
    function month() {
        var tools=hxsd_tools();
        var oVisa=document.getElementById('visa_date');
        var oRmb=document.getElementById('rmb');
        var oB=oVisa.getElementsByTagName('b');
        for(var i=0; i<oB.length; i++){
            var price = parseInt(oRmb.innerHTML);
            var j=i+1;
            var month=0;
            if(i==0||i==1){
                month=3*j
            }else if(i==2){
                month=4*j
            }else if(i==3){
                month=6*j
            };
            var permonth = price * Math.pow(1.005, month)*n / (month);
            oB[i].innerHTML = permonth.toFixed(2);
        }
    }
}


//下拉菜单展开
function addresslist(elmid,contid){//移入某处，展示对象，
    var tools=hxsd_tools();
    var oElm=document.getElementById(elmid);
    var oBox=document.getElementById(contid);
    var oBtn=tools.getClassName(oBox,'close');
    oElm.onmouseover=function(){
        this.className='place hover';
        oBox.style.display='block';
    }
    oBtn[0].onclick=function(){
        oBox.style.display='none';
        oElm.className='place';
    }
}

//点击内容切换至下一张选项卡
function cont_change(id){
    var tools=hxsd_tools();
    var oBox=document.getElementById('address_box');
    var oElm=document.getElementById('nowwhere');
    var oTitle=document.getElementById('address_title');
    var aTitle=oTitle.getElementsByTagName('li');
    var oAdsBox=document.getElementById('adsBox');
    var aCont=tools.getClassName(oAdsBox,'cont');
    var oCont=document.getElementById(id);
    var aLi=oCont.getElementsByTagName('li');
    var n=parseInt(id.replace(/[^0-9]/g,"")-1);
    for(var i=0; i<aLi.length; i++){
        aLi[i].onclick=function(){
            aTitle[n].children[0].innerHTML=this.children[0].innerHTML;
            if(n==aTitle.length-1){
                oBox.style.display='none';
                oElm.className='place';
                text_to();
                return;
            }
            aTitle[n].children[0].innerHTML=this.children[0].innerHTML;
            for(var j=0; j<aTitle.length;j++){
                aTitle[j].className='';
                oCont.className='cont';
            }
            aCont[n+1].className='cont active';
            aTitle[n+1].className='active';

            text_to()
        }
    }
}
//地址置入地址栏
function text_to() {
    var oBox=document.getElementById('address_title');
    var aLi=oBox.getElementsByTagName('li');
    var oText=document.getElementById('nowwhere');
    var text=[];
    for(var i=0; i<aLi.length; i++){
        text.push(aLi[i].children[0].innerHTML);
    }
    var text=text.toString();
    var text=text.replace(/,/g,"");
    oText.children[0].innerHTML=text;
}
